<template>
  <div>
    <div style="width:550px;height:300px;border:#ccc solid 1px;font-size:12px" id="map"></div>
  </div>
</template>

<script>
// import BMap from 'BMap'
export default {
  data () {
    return {
      map: {}
    }
  },
  mounted() {
    // this.createMap();//创建地图
    // this.setMapEvent();//设置地图事件
    // this.addMapControl();//向地图添加控件
    // this.addMapOverlay();//向地图添加覆盖物
  },
  methods: {
    createMap () {
      this.map = new BMap.Map("map");
      this.map.centerAndZoom(new BMap.Point(118.183685,24.498945),18);
    },
    setMapEvent(){
      this.map.enableScrollWheelZoom();
      this.map.enableKeyboard();
      this.map.enableDragging();
      this.map.enableDoubleClickZoom()
    },
    addClickHandler (target,window) {
      target.addEventListener("click",function(){
        target.openInfoWindow(window);
      });
    },
    addMapOverlay () {
      var markers = [
        {content:"地址：厦门市软件园二期望海路19号302单元",title:"中语智慧",imageOffset: {width:-46,height:-21},position:{lat:24.499117,lng:118.183945}}
      ];
      for(var index = 0; index < markers.length; index++ ){
        var point = new BMap.Point(markers[index].position.lng,markers[index].position.lat);
        var marker = new BMap.Marker(point,{icon:new BMap.Icon("http://api.map.baidu.com/lbsapi/createmap/images/icon.png",new BMap.Size(20,25),{
          imageOffset: new BMap.Size(markers[index].imageOffset.width,markers[index].imageOffset.height)
        })});
        var label = new BMap.Label(markers[index].title,{offset: new BMap.Size(25,5)});
        var opts = {
          width: 200,
          title: markers[index].title,
          enableMessage: false
        };
        var infoWindow = new BMap.InfoWindow(markers[index].content,opts);
        marker.setLabel(label);
        this.addClickHandler(marker,infoWindow);
        this.map.addOverlay(marker);
      };
      var labels = [
      ];
      for(var index = 0; index < labels.length; index++){
        var opt = { position: new BMap.Point(labels[index].position.lng,labels[index].position.lat )};
        var label = new BMap.Label(labels[index].content,opt);
        this.map.addOverlay(label);
      };
    },
    addMapControl(){
      var navControl = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:3});
      this.map.addControl(navControl);
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
